package com.ruoyi.management.branch.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.management.branch.domain.TBranch;
import com.ruoyi.management.branch.service.ITBranchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分行代码维护
 * 
 * @author ruoyi
 * @date 2021-12-07
 */
@Api(tags = "分行代码维护")
@RestController
@RequestMapping("/branch/branch")
public class TBranchController extends BaseController
{
    @Autowired
    private ITBranchService tBranchService;

    /**
     * 查询分行列表
     */
    @GetMapping("/list")
    @ApiOperation("查询分行代码列表")
    public TableDataInfo list(TBranch tBranch)
    {
        startPage();
        List<TBranch> list = tBranchService.selectTBranchList(tBranch);
        return getDataTable(list);
    }

    /**
     * 导出分行列表
     */
    @Log(title = "分行", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出分行代码")
    public AjaxResult export(TBranch tBranch)
    {
        List<TBranch> list = tBranchService.selectTBranchList(tBranch);
        ExcelUtil<TBranch> util = new ExcelUtil<TBranch>(TBranch.class);
        return util.exportExcel(list, "分行数据");
    }

    /**
     * 获取分行详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取分行代码详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tBranchService.selectTBranchById(id));
    }

    /**
     * 新增分行
     */
    @Log(title = "分行", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增分行代码")
    public AjaxResult add(@RequestBody TBranch tBranch)
    {
        return toAjax(tBranchService.insertTBranch(tBranch));
    }

    /**
     * 修改分行
     */
    @Log(title = "分行", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改分行代码")
    public AjaxResult edit(@RequestBody TBranch tBranch)
    {
        return toAjax(tBranchService.updateTBranch(tBranch));
    }

    /**
     * 删除分行
     */
    @Log(title = "分行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除分行代码")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBranchService.deleteTBranchByIds(ids));
    }

    /**
     * {TODO}
     *分行下拉选框
     * @param  * @param
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @throws
     * @Author: xly
     */
    @GetMapping("branchs")
    @ApiOperation("分行下拉选框")
    public AjaxResult branchs(){
        return AjaxResult.success(tBranchService.branchs());
    }
}
